//
//  Array.swift
//  Wallet
//
//  Created by Julian on 2022/5/7.
//

import Foundation

public extension Array{
    /// 将数组转换为字典形式
    func toDict(_ f:(Element)->String)->Dictionary<String,[Element]>{
        var dict = Dictionary<String,[Element]>()
        for item in self {
            if dict[f(item)] == nil {
                dict[f(item)] = [item]
            }else{
                dict[f(item)]!.append(item)
            }
        }
        return dict
    }
}
